/*  Getpriority.c - Try to show that hogging the CPU worsens the priority.
*/

#include <stdio.h>
#include <sys/resource.h>
#include <sched.h>
#include "loop.h"

#define N 1024

int main(int argc, char* argv[]) {
    int i;
    int old = getpriority(PRIO_PROCESS, 0);
    struct sched_param param;
    sched_getparam(0, &param);
    int par = param.sched_priority;
    printf("pri=%d\n", old);
    for(i=0; i < N; i++) {
        int new = getpriority(PRIO_PROCESS, 0);
        sched_getparam(0, &param);
        if(old != new || par != param.sched_priority) {
            old = new;
            par = param.sched_priority;
            printf("i=%d, pri=%d, par=%d\n", i, new, par);
        }
        loop(100);
    }
    return 0;
}

/*  Please note that the checks on the return value of the system calls
    have been omitted to avoid cluttering the code. However, system calls
    can and will fail, in which case the results are unpredictable. */
